﻿using Pdoxcl2Sharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace V3MainTool.Model
{
    /// <summary>
    /// 省份
    /// </summary>
    public class GoodsFamily : IParadoxRead, IParadoxWrite
    {
        public List<Goods> MyList { get; set; }
        public GoodsFamily()
        {
            MyList = new List<Goods>();
        }

        public void TokenCallback(ParadoxParser parser, string token)
        {
            Goods item = parser.Parse(new Goods());
            item.name = token;
            MyList.Add(item);
        }

        public void Write(ParadoxStreamWriter writer)
        {
            for (int i = 0; i < MyList.Count; i++)
            {
                writer.Write(MyList[i].name, MyList[i]);
            }
        }
    }
    public class Goods : IParadoxRead, IParadoxWrite
    {
        #region 转换
        public string nameStr
        {
            get
            {
                Dictionary<string, string> dic = LocalHelper.Goods;
                if (dic.TryGetValue(name, out string val))
                {
                    return val;
                }
                return name;
            }
        }
        public string categoryStr
        {
            get
            {
                Dictionary<string, string> dic = LocalHelper.GoodsCate;
                if (dic.TryGetValue(category, out string val))
                {
                    return val;
                }
                return category;
            }
        }
        #endregion
        public string name { get; set; }
        public string texture { get; set; }
        public int? cost { get; set; }
        public string category { get; set; }
        public string tradeable { get; set; }
        /// <summary>
        /// 成瘾几率
        /// </summary>
        public double? obsession_chance { get; set; }
        /// <summary>
        /// 威望系数
        /// </summary>
        public int? prestige_factor { get; set; }
        /// <summary>
        /// 护航系数
        /// </summary>
        public int? convoy_shipping_multiplier { get; set; }
        /// <summary>
        /// 贸易系数
        /// </summary>
        public int? trade_route_revenue_multiplier { get; set; }
        /// <summary>
        /// 固定价格
        /// </summary>
        public string fixed_price { get; set; }
      
        public void TokenCallback(ParadoxParser parser, string token)
        {
            switch (token)
            {
                case "texture": texture = parser.ReadString(); break;
                case "cost": cost = parser.ReadInt32(); break;
                case "category": category = parser.ReadString(); break;
                case "tradeable": tradeable = parser.ReadString(); break;
                case "obsession_chance": obsession_chance = parser.ReadDouble(); break;
                case "prestige_factor": prestige_factor = parser.ReadInt32(); break;
                case "convoy_shipping_multiplier": convoy_shipping_multiplier = parser.ReadInt32(); break;
                case "trade_route_revenue_multiplier": trade_route_revenue_multiplier = parser.ReadInt32(); break;
                case "fixed_price": fixed_price = parser.ReadString(); break;
                default:
                    Console.WriteLine("unknow Goods prop:  " + token);
                    break;
            }
        }

        public void Write(ParadoxStreamWriter writer)
        {
            if (texture != null) writer.WriteLine("texture", texture, ValueWrite.Quoted);
            if (cost != null) writer.WriteLine("cost", cost.Value);
            if (category != null) writer.WriteLine("category", category);
            if (tradeable != null) writer.WriteLine("tradeable", tradeable);
            if (obsession_chance != null) writer.WriteLine("obsession_chance", obsession_chance.Value);
            if (prestige_factor != null) writer.WriteLine("prestige_factor", prestige_factor.Value);
            if (convoy_shipping_multiplier != null) writer.WriteLine("convoy_shipping_multiplier", convoy_shipping_multiplier.Value);
            if (trade_route_revenue_multiplier != null) writer.WriteLine("trade_route_revenue_multiplier", trade_route_revenue_multiplier.Value);
            if (fixed_price != null) writer.WriteLine("fixed_price", fixed_price);
          
        }
    }
}
